package IO_demo.objectStream;

import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.*;
import java.time.Period;
import java.util.ArrayList;

/**
 * @author Summerday
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Person implements Serializable {

    private String name;
    private int age;



    private void writeObject(ObjectOutputStream out) throws IOException {
        out.writeObject(new StringBuffer(name).reverse());
        out.writeInt(age);
    }

    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        this.name =( (StringBuffer)in.readObject()).reverse().toString();
        this.age = in.readInt();
    }

/*    private Object writeReplace(){
        ArrayList<Object> list = new ArrayList<>();
        list.add(name);
        list.add(age);
        return list;
    }*/
}
